/**
 * Created by 骆鹏 on 2017/7/27.
 */
var flowId
var formId
$(function () {
    $.get('/document/sortFlow',{mainType:'DOCUMENTTYPE',detailType:'SENDNG'},function (json) {
        var width = $('.tableDl').width() * 0.2 * 0.94 - 30;
        if(json.flag&&json.datas!=undefined){
            $('.noData').hide();
            var arr=json.datas;
            var str=''
            for(var i=0;i<arr.length;i++){
                str+='<dl>\
                        <dt>\
                            <img src="/img/sys/icon_organizationmanagement_03.png" alt=""> \
                            <span title="'+arr[i].sortName+'" style="width: '+ width +';">'+arr[i].sortName+'</span>\
                        </dt>\
                        <dd>\
                            <ul>\
                            '+function () {
                                var arrys=arr[i].flows;
                                var strflows=''
                                for(var m=0;m<arrys.length;m++){
                                    strflows+='<li data-id="1" data-urlid="'+arrys[m].flowId+'" data-name="'+arrys[m].flowName+'" flowId="'+arrys[m].flowId+'" formId="'+arrys[m].formId+'">\
                                                <b></b>\
                                                <a  \
                                                href="javascript:void(0)"  >\
                                                '+arrys[m].flowName+'</a>\
                                               </li>'
                                }
                                return strflows;
                             }()+'\
                            </ul>\
                        </dd>\
                      </dl>'
            }

            if(arr.length==0){
                str='<div style="position: relative;height: 100%">' +
                        '<div style="position: absolute;width: 100px;height: 130px;' +
                    'top: 38%;margin-top: -50px;left: 50%;margin-left: -50px;">' +
                            '<img src="/img/common/dianjikong.png" alt="">' +
                            '<p style="text-align: center;font-size: 11pt;color: #000;margin-top: 10px;' +
                    'padding-left: 12px;">'+no_Data+'</p>' +
                        '</div>' +
                    '</div>'

            }
            $('.tableDl').html(str)
        }else{
            $('.noData').show();
        }
    },'json')
    
    
    
    $('.tableDl').delegate('[data-id="1"]','click',function () {
        var urlid=$(this).attr('data-urlid');
        var runId=null;
        var runName=null;
        var flowName=$(this).attr("data-name");
        flowId=$(this).attr("flowId");
        formId=$(this).attr("formId");
        (function (fn) {
            $.post('/document/getRunName',{flowId:urlid,runId:'',prcsId:1,flowStep:1},function (json) {
                if(json.flag){
                    // runId=json.data;
                    runName=json.data;
                    if(fn!=undefined){
                        fn()
                    }
                }

            },'json')
        })(function () {
            if(runName == ''){
                runName = flowName;
            }
            var loadindex = layer.load();
            $.ajax({
                url:'/document/saveDoc',
                type:'post',
                dataType:'json',
                data:{
                    title:runName,
                    flowId:urlid,
                    documentType:0,
                    dispatchType:'',
                    fflowId:urlid,
                    frunId:'',
                    fprcsId:1,
                    fflowStep:1,
                    frunName:runName,
                    sysRuleId: 0
                },
                async: false,//同步请求,这里使用ajax必须使用同步方式请求，因为浏览器认为这种打开在ajax后新页面是不安全的
                success:function(json){
                    layer.close(loadindex);
                    if(json.flag){
                        $.layerMsg({content:save,icon:1},function () {
                        });
                        $.popWindow('/workflow/work/workform?IE=1&flowId='+json.object.flowId+'&flowStep=1&tableName=document&tabId='+json.object.id+'&runId='+json.object.runId+'&prcsId=1&isNomalType=false')
                    }else {
                        $.layerMsg({content:json.msg,icon:2});
                    }
                }
            });

        })


    })
    //点击流程说明
    $(document).on('click','.liucheng2',function(){
       /* var flowId=$(this).parents('.sort_new').attr('tid');
        var formId=$(this).parents('.sort_new').attr('formid');
        var word=$(this).parent().siblings('.rig_left').find('h1').text();*/
        $.popWindow("/workflow/work/processSpeak?flowId="+flowId+'&formId='+formId,'流程说明','0','0','1150px','700px');
    })
})